/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: GoodsbillMasterServiceImpl
 * Author:   李毅
 * Date:     2019/10/18 10:21
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.ymtms.supplycar.service.impl;

import com.ymtms.supplycar.dao.GoodsbillMasterMapper;
import com.ymtms.supplycar.exception.CarException;
import com.ymtms.supplycar.pojo.GoodsbillMaster;
import com.ymtms.supplycar.pojo.Waybill;
import com.ymtms.supplycar.service.GoodsbillMasterService;
import com.ymtms.supplycar.vo.GridRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈业务实现类〉
 *
 * @author 李毅
 * @create 2019/10/18
 * @since 1.0.0
 */
@Service
public class GoodsbillMasterServiceImpl implements GoodsbillMasterService {

    @Autowired
    private GoodsbillMasterMapper goodsbillMasterMapper;

    @Override
    public GoodsbillMaster findGoodsbillByGid(Integer gid) {
        GoodsbillMaster goodsbillMaster = goodsbillMasterMapper.selectByPrimaryKey(gid);
        if (goodsbillMaster == null){
            throw new CarException("查询数据为空，请重试！");
        }
        return goodsbillMaster;
    }

    @Override
    public List<GoodsbillMaster> findGoodsbillByState(String state, GridRequest gridRequest) {
        Integer begin = (gridRequest.getPage()-1) * gridRequest.getLimit();
        Integer end = gridRequest.getLimit();
        List<GoodsbillMaster> list = goodsbillMasterMapper.getAllByState(state,begin,end);
        if (list.isEmpty()){
            throw new CarException("查询状态为空，请重试!");
        }
        return list;
    }

    @Override
    public Integer findCount(String state) {
        int count = goodsbillMasterMapper.selectTotalCount(state);
        if (count==0){
            throw new CarException("查询数量失败，请重试！");
        }
        return count;
    }

    @Override
    public List<GoodsbillMaster> findAllByState(String state) {
        List<GoodsbillMaster> goodsbillMasters = goodsbillMasterMapper.selectAllByState(state);
        if (goodsbillMasters.isEmpty()){
            throw new CarException("查询数据为空，请重试!");
        }
        return goodsbillMasters;
    }

    /**
     * @Description 根据职员账号login_id查询该职员所负责的货运单
     * @Param login_id 职员账号
     * @return list集合
     * @date   2019/11/6  9:25
     * @author 张泓
     */
    @Override
    public List<GoodsbillMaster> getGoodsbillMasterByLoginId(String login_id) {
        return goodsbillMasterMapper.selectGoodsbillMasterByLoginId(login_id);
    }




}